<template>
  <div class="dialog">
    <div class="dialog-head" @click="backToMsgList">
      <i class="iconfont iconarrow-left dialog-back"></i>
      {{currentCompany.name}}
    </div>
    <div class="dialog-body">
      <div class="dialog-body-item dialog-company">
        <img :src="currentCompany.imgUrl" />
        <div class="company-text">bsfasdasdas</div>
      </div>
      <div class="dialog-body-item dialog-self">
        <div class="company-text">1233123213</div>
        <img :src="currentCompany.imgUrl" />
      </div>
    </div>
    <div class="dialog-foot">
      <input type="text" v-model="sendText" />
      <button @click="sendMsg">发送</button>
    </div>
  </div>
</template>

<script>
export default {
  name: "TalkDialog",
  data() {
    return {
      ws: "",
      sendText:""
    };
  },
  props: ["currentCompany"],
  methods: {
    backToMsgList(){
      this.$emit("back")
    },
    sendMsg() {
      // 获得用户输入问题
      // console.log(this.sendText)
      this.selfText[this.idx] = this.sendText;
      this.idx++;
      this.ws.onopen = () => {
        this.ws.send(this.sendText);
      };
      // 发送完成后清空输入框
      this.sendText = "";
      this.receiveMsg();
    },
    receiveMsg() {
      this.ws.onmessage = event => {
        if (event.data) {
          return;
        } else {
          console.log(event.data)
        }
      };
    }
  },
  mounted() {
    // 连接服务器，暂时没有，设置为本地，无返回无作用
    this.ws = new WebSocket("ws://localhost:8080");
  }
};
</script>

<style scoped="scoped" lang="scss">
.dialog {
  height: 93%;
  overflow-x: hidden;
  background-color: #f3f3f3;
  .dialog-head {
    width: 100%;
    height: 5%;
    line-height: 2em;
    font-weight: bold;
    background-color: #bfd6d9;
    font-size: 16px;
    .dialog-back{
      transform: rotateX(-50deg);
    }
  }
  .dialog-body {
    width: 100%;
    height: 90%;
    overflow-y: scroll;
    .dialog-body-item {
      margin-top: 2em;
      display: flex;
      height: 60px;
      img {
        width: 60px;
        height: 60px;
        border-radius: 50%;
      }
      .company-text {
        height: 50px;
        margin: 0 1em;
        border-radius: 12px;
        font-size: 14px;
        padding: 1.3em 1em;
        background-color: #fff;
        box-sizing: border-box;
        position: relative;
      }
      .company-text::before {
        content: "";
        position: absolute;
        border: 10px solid;
        border-color: transparent #fff transparent transparent;
        top: 50%;
        left: -8%;
        transform: translateY(-50%);
      }
    }
    .dialog-self {
      width: 100%;
      justify-content: flex-end;
      .company-text {
        background-color: #00bfff;
        color: #fff;
      }
      .company-text::before {
        content: "";
        position: absolute;
        border: 10px solid;
        border-color: transparent transparent transparent #00bfff;
        top: 50%;
        left: 100%;
        transform: translateY(-50%);
      }
    }
  }
  .dialog-foot {
    width: 100%;
    height: 5%;
    display: flex;
    input {
      display: block;
      width: 80%;
      height: 100%;
      padding-left: 1em;
    }
    button {
      display: block;
      width: 20%;
      height: 100%;
      color: #fff;
      background-color: #00bfff;
    }
  }
}
</style>
